/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * gftp-file.c : 
 *
 * Copyright (C) 2008, 2009 Lingtao Pan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA 02111-1307, USA.
 */

#include "gftp.h"

gftp_file*
gftp_file_copy (gftp_file *fle)
{
    gftp_file * newfle;

    newfle = g_malloc0 (sizeof (*newfle));
    memcpy (newfle, fle, sizeof (*newfle));

    if (fle->file)
        newfle->file = g_strdup (fle->file);

    if (fle->user)
        newfle->user = g_strdup (fle->user);

    if (fle->group)
        newfle->group = g_strdup (fle->group);

    if (fle->destfile)
        newfle->destfile = g_strdup (fle->destfile);

    return (newfle);
}

void
free_file_list (GList *filelist)
{
    gftp_file * tempfle;
    GList * templist;

    templist = filelist;
    while (templist != NULL)
    {
        tempfle = templist->data;
        gftp_file_destroy (tempfle, 1);
        templist = templist->next;
    }
    g_list_free (filelist);    
}


void
gftp_file_destroy (gftp_file *file, int free_it)
{
    g_return_if_fail (file != NULL);

    if (file->file)
        g_free (file->file);
    if (file->user)
        g_free (file->user);
    if (file->group)
        g_free (file->group);
    if (file->destfile)
        g_free (file->destfile);

    if (free_it)
        g_free (file);
    else
        memset (file, 0, sizeof (*file));
}

